﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace memcached
{
    /// <summary>
    /// Advanced cache store interface.
    /// </summary>
    /// <remarks>Methods return false upon failure, no cache-originating exceptions allowed.</remarks>
    public interface ICacheAdvanced : ICache
    {
        /// <summary>
        /// Increment integer value or set to initial value if does not exist yet.
        /// </summary>
        /// <remarks>Not thread safe if value not yet exists.</remarks>
        /// <param name="key">not null</param>
        /// <param name="startAt">non negative value</param>
        /// <returns>new value of an item</returns>
        long Increment(string key, long startAt);

        /// <summary>
        /// Decrement positive integer value.
        /// </summary>
        /// <param name="key">not null</param>
        /// <returns>new value of an item, -1 if item not found</returns>
        long Decrement(string key);

        /// <summary>
        /// Set value provided CAS value is still valid.
        /// </summary>
        /// <param name="key">not null</param>
        /// <param name="cas"></param>
        /// <param name="value">not null</param>
        /// <returns>operation failed or CAS value is no longer valid</returns>
        bool Set(string key, ulong cas, object value);

        /// <summary>
        /// Get item value and CAS value for it.
        /// </summary>
        /// <typeparam name="T">type of item value</typeparam>
        /// <param name="key">not null</param>
        /// <returns>null if key not found or invalid type</returns>
        CasValue<T> Get<T>(string key);
    }
}